package com.lw.yygh.hosp.common;

import com.lw.yygh.exception.YyghException;
import com.lw.yygh.hosp.service.HospSetService;
import com.lw.yygh.result.ResultCodeEnum;
import com.lw.yygh.utils.HttpRequestHelper;
import com.lw.yygh.utils.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Component
public class GetParameterAndCheck {
    @Autowired
    private HospSetService hospSetService;
    public  Map<String, Object> getParameterAndCheck(HttpServletRequest request){
        //获取传递过来的参数
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String, Object> map = HttpRequestHelper.switchMap( parameterMap );
        //12.获取医院系统传过来的MD5加密签名
        String sign = (String) map.get( "sign" );
        String hoscode = (String) map.get( "hoscode" );
        String sinKey=hospSetService.getSignKey(hoscode);
        String signKeyMD5 = MD5.encrypt( sinKey );
        if (!sign.equals( signKeyMD5 )){
            throw new YyghException( ResultCodeEnum.SIGN_ERROR );
        }
        return map;
    }
}
